package crm.model.studentPC;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

import crm.model.Setting;

public class SendThread extends Thread {
	StudentPcService service;
	public SendThread(StudentPcService service) {
		this.service = service;
	}

	public void run() {
		try {
			while(!service.isConnected){
				DatagramSocket udpSocket = new DatagramSocket();
				udpSocket.setBroadcast(true);
				byte[] buffer = "Student".getBytes();
				DatagramPacket packet = new DatagramPacket(buffer, buffer.length, InetAddress.getByName(Setting.getBroadcastAddress()), Setting.getReceivePort());
				udpSocket.send(packet);
				udpSocket.close();

				try {
					Thread.sleep(10000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
